package com.qf.web.servlet;


import cn.dsna.util.images.ValidateCode;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * Create by 周志豪 on 2022/8/16 20:10
 *
 * @authoe 周志豪
 * @veision 1.0
 * //TODO  想好了再去做
 * @since 1.0
 */

public class CodeServlet {

    public void createCode(HttpServletRequest request, HttpServletResponse response) {
        ValidateCode validateCode = new ValidateCode(140, 60, 4, 10);
        String code = validateCode.getCode();
        request.getSession().setAttribute("code", code);
        BufferedImage buffImg = validateCode.getBuffImg();
        try {
            ImageIO.write(buffImg, "jpg", response.getOutputStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
